﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CUREBusinessLogicLayer;
using CUREEntity;
using CURE.Handler;
using System.Data;

namespace CURE.SystemManagement
{
    public partial class EventLog : System.Web.UI.Page
    {
        #region 分页变量，与UI绑定
        private int numPerPage;
        /// <summary>
        /// 每页显示的条数


        /// </summary>
        public int NumPerPage
        {
            get
            {
                int temp = Convert.ToInt32(Request.Form["numPerPage"]);
                return temp == 0 ? 20 : temp;
            }
            set { numPerPage = value; }
        }

        private int pageNumShown = 10;
        /// <summary>
        /// 页数导航的个数


        /// </summary>
        public int PageNumShown
        {
            get { return pageNumShown; }
            set { pageNumShown = value; }
        }

        private int pageNum;
        /// <summary>
        /// 当前显示的页数


        /// </summary>
        public int PageNum
        {
            get
            {
                int temp = Convert.ToInt32(Request.Form["pageNum"]);
                return temp == 0 ? 1 : temp;
            }
            set { pageNum = value; }
        }

        private int totalCount;
        /// <summary>
        /// 总条数


        /// </summary>
        public int TotalCount
        {
            get { return totalCount; }
            set { totalCount = value; }
        }

        private string keywords;
        /// <summary>
        /// where语句，不加where与空格


        /// </summary>
        public string Keywords
        {
            get
            {
                string temp = Request.Form["keywords"];
                return temp;
            }
            set { keywords = value; }
        }



        private string orderField;
        /// <summary>
        /// 排序关键字


        /// </summary>
        public string OrderField
        {
            get
            {
                string temp = Request.Form["orderField"];
                return temp;
            }
            set { orderField = value; }
        }
        #endregion

        #region 变量
        private string startdate;

        public string Startdate
        {
            get { return startdate; }
            set { startdate = value; }
        }
        private string enddate;

        public string Enddate
        {
            get { return enddate; }
            set { enddate = value; }
        }

        private string type;

        public string Type
        {
            get { return type; }
            set { type = value; }
        }
        #endregion

        EventLogBll eventlogbll = new EventLogBll();
        protected void Page_Load(object sender, EventArgs e)
        {
            JudgeAuthority ja = new JudgeAuthority();
            if (ja.JudgeUserAuthorityByGroupId("SystemManagement/EventLog.aspx"))
            {
                type = Request.Form["select_timelog"];
                startdate = Request.Form["txtStarDateLog"];
                enddate = Request.Form["txtEndDateLog"];
                if (string.IsNullOrEmpty(startdate))
                {
                    startdate = DateTime.Now.ToString("yyyy-MM-dd");
                }
                if (string.IsNullOrEmpty(enddate))
                {
                    enddate = DateTime.Now.ToString("yyyy-MM-dd");
                }
                if (string.IsNullOrEmpty(type))
                {
                    type = "1";
                }
                if (DateTime.Parse(startdate) > DateTime.Parse(enddate))
                {
                    Response.Write("<script>alertMsg.error('开始日期不能大于结束日期！');</script>");
                }
                else
                {
                    GetEventLogData();
                }
            }
            else
            {
                Response.Write("<script language=javascript>top.location.href='../../Login.aspx';</script>");
                Response.End();
            }
        }

        public void GetEventLogData()
        {
            Dictionary<string, object> dic = new Dictionary<string, object>();
            dic.Add("type", type);
            dic.Add("startdate", startdate);
            dic.Add("enddate", enddate);
            int totalPageCount;
            DataSet ds = eventlogbll.GetEventLogData(dic, PageNum, NumPerPage, out totalCount, out totalPageCount);
            if (ds != null)
            {
                RepeaterDept.DataSource = ds;
                RepeaterDept.DataBind();
            }

        }
    }
}